import type { App } from "vue";
import { register } from "@/core/register";
import { router } from "@/router/index";
import pages from "@/pages/index";
import { components } from "@/components/index";

class VueInitPlugin {
  // 插件安装
  install(app: App) {
    this.initPages();
    this.componentResiter(app);
  }
  private initPages() {
    pages.forEach((page) => {
      register.registerPage(page);

      router.addRoute({
        path: page.getPath(),
        component: null as any,
      });
    });
  }
  componentResiter(app: App) {
    Object.keys(components).forEach((comp) => {
      app.component(comp, components[comp]);
    });
  }
}

export const vueInitPlugin = new VueInitPlugin();
